package com.terrapages.wmsc4j.example;

import java.awt.Dimension;

import org.apache.log4j.Logger;

import com.terrapages.wmsc4j.bean.BBox;
import com.terrapages.wmsc4j.bean.Pos;
import com.terrapages.wmsc4j.layer.AbstractLayer;
import com.terrapages.wmsc4j.layer.StaticLayer;
import com.terrapages.wmsc4j.layer.resolution.Resolution;
import com.terrapages.wmsc4j.layer.resolution.ResolutionSet;
import com.terrapages.wmsc4j.layer.tile.ImageMimeType;
import com.terrapages.wmsc4j.layer.tile.Tile;
import com.terrapages.wmsc4j.layer.tile.TileFormat;

/**
 * Example code which illistrates the use of Sub Coverage Layer and layer iteration.
 * @author mvivian
 */
public class SubCoverageLayerExample {

	private static Logger log = Logger.getLogger(SubCoverageLayerExample.class);
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final ResolutionSet resolutions = new ResolutionSet(new Resolution(0.703125),20);
		final BBox coverage = new BBox(-180,-90,180,90);
		
		
		final AbstractLayer geoserverLayer = new StaticLayer(
			null,//Layer has no cache, thus the null
			resolutions,
			new TileFormat(new Dimension(256,256), ImageMimeType.PNG),
			coverage,
			new Pos(-180,-90),
			"Geoserver"
		);
		
//		 Adelaide boundingbox
		BBox extent = new BBox(138.515625,-34.980469,138.691406,-34.804687);
		
		//Limits the the layer to the boundingbox extent and between the zoom levels of 2 and 4 inclusive
		final AbstractLayer subLayer = geoserverLayer.getSubCoverageLayer(extent, 2, 4);
		
		//Iterate through all the tiles in Adelaide at the zoom levels 2 through 4
		for(Tile tile: subLayer)
		{
			log.info(tile);
		}
	}
}
